Micron Document




JavaScript syntax
part 36/59 · 107.4 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
console.log(c.length);
}
foo(1, 2, 3, 4, 5); // "3" → c = [3, 4, 5]
foo('a', 'b'); // "0" → c = []

Rest parameters are similar to Javascript's arguments object, which is an array-like object that contains all of the parameters (named and unnamed) in the current function call. Unlike arguments, however, rest parameters are true Array objects, so methods such as .slice() and .sort() can be used on them directly.

Comparison

| == | equal |
|---|---|
| != | not equal |
| > | greater than |
| >= | greater than or equal to |
| < | less than |
| <= | less than or equal to |
| === | identical (equal and of same type) |
| !== | not identical |

Variables referencing objects are equal or identical only if they reference the same object:

const obj1 = {a: 1};
const obj2 = {a: 1};
const obj3 = obj1;
console.log(obj1 == obj2); //false
console.log(obj3 == obj1); //true
console.log(obj3 === obj1); //true

See also String.

Logical

JavaScript provides four logical operators:

• unary negation (NOT = !a)
• binary disjunction (OR = a || b) and conjunction (AND = a && b)
• ternary conditional (c ? t : f)

In the context of a logical operation, any expression evaluates to true except the following:

• Strings: "", '',
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────